#include <stdio.h>
#include <stdlib.h>
#include "comm/annex_b.h"


void annexb_parse_fp_cb(FILE *fp, nalu_t *nalu, void *userdata)
{
	printf("startcode_len:%d buf_len:%ld\n", nalu->startcode_len, nalu->buf_len);
	
	u8 type = 0;
	void *res = nalu_parse(nalu, &type);
	if (nalu_type_sps == type)
	{
		for (size_t i = 0; i < nalu->buf_len; i++)
		{
			printf("%02x ", nalu->buf[i]);
		}
		nalu_sps_t *sps = (nalu_sps_t *) res;
	}
	else
	{
		printf("type:%d\n", type);
	}
	printf("\n");
	nalu_deinit(res, type);
}

int main(void)
{
	#if 1
	const char *path = "/home/luqingliang/Downloads/sxdj.h264";
	FILE* fp = fopen(path, "rb");
	if (fp != NULL)
	{
		annexb_parse_fp(fp, NULL, annexb_parse_fp_cb);
		fclose(fp);
	}
	else
	{
		perror("fopen()");
	}
	return 0;
#else
	s264buf_t buf;
	s264buf_init(&buf, 255);
	u8 c = 'a';
	for (size_t i = 0; i < 48; i++)
	{
		/* code */
		s264buf_append(&buf, &c, 1);
		c++;
	}
	for (size_t i = 0; i < buf.len; i++)
	{
		printf("%c ", buf.data[i]);
	}
	printf("\n");

	s264buf_deinit(&buf);
	#endif
}